package com.example.lifecycle;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;

public class ActivityLifecycle extends Activity {
	
	public static final int INPUT_STRING_REQUEST = 1;
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Toast.makeText(getApplicationContext(), "onCreate", Toast.LENGTH_SHORT).show();
        

        // UPGRADE
    	Intent intent = new Intent();
    	intent.putExtra("textParam", "Brasil");
    	intent.setComponent(new ComponentName("com.example.helloworld", "com.example.helloworld.HelloActivity"));
    	startActivityForResult(intent, INPUT_STRING_REQUEST);
    }

    @Override
    protected void onDestroy() {
    	// TODO Auto-generated method stub
    	super.onDestroy();
    	
    	Toast.makeText(getApplicationContext(), "onDestroy", Toast.LENGTH_SHORT).show();
    }


    @Override
    protected void onResume() {
    	// TODO Auto-generated method stub
    	super.onResume();
    	
    	Toast.makeText(getApplicationContext(), "onResume", Toast.LENGTH_SHORT).show();
   }


    @Override
    protected void onPause() {
    	// TODO Auto-generated method stub
    	super.onPause();
    	
    	Toast.makeText(getApplicationContext(), "onPause", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onStart() {
    	// TODO Auto-generated method stub
    	super.onStart();
    	
    	Toast.makeText(getApplicationContext(), "onStart", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onStop() {
    	// TODO Auto-generated method stub
    	super.onStop();
    	
    	Toast.makeText(getApplicationContext(), "onStop", Toast.LENGTH_SHORT).show();
    }
    
    
    // UPGRADE
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	// TODO Auto-generated method stub
    	super.onActivityResult(requestCode, resultCode, data);
    	
    	if (requestCode == INPUT_STRING_REQUEST)
    		if (resultCode == RESULT_OK) {
    			Uri uri = Uri.parse("http://www.google.com.br/m/search?q=" + data.getStringExtra("resultText"));
    			startActivity(new Intent(Intent.ACTION_VIEW, uri));	
    		}   		 
    }
}
